import time
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication

now = time.strftime('$Y-%m-%d_%H_%M_%S')#获取时间戳

_user = ""
_pwd = ""

class sendEmail:
    def send_email(self,send_obj,filepath):
        #send_obj，接收方
        #filepath 附件地址
        msg = MIMEMultipart()
        msg['Subject'] = now+"测试报告"
        msg['From'] = _user
        msg['To'] = send_obj

        #文字输出

        #附件上传
        path = ['1','2','3']
        for item in path:
            part = MIMEApplication(open(item,'rb').read())
            part.add_header('Content-Disposition','aattachment',filepath=filepath)
            msg.attach(part)
        ser_ssl = smtplib.SMTP_SSL("smtp.qq.com",timeout=30)#邮件服务器
        ser_ssl.login(_user,_pwd)#登录服务器
        ser_ssl.sendmail(_user,send_obj,msg.as_string())#发送邮件
        ser_ssl.close()

if __name__ == '__main__':
    sendEmail().send_email("igumi@outlook.com",r"C:\Users\Vanthic Noeik\Desktop\微信截图_20240909220653.png")